import math
import random
import pandas as pd
from Core.Config import *
config = Config()

database = config.DataBase()
mysql = config.Mysql()
a = mysql.Find("rec_article","article_tag")
articles = {}
article_list = []
documents = []
for i in range(len(a)):
    article = a[i]["article_id"]
    if article not in articles:
        articles[article] = {}
        article_list.append(article)
a = database.Count("Recommender", "UserAction_Plus")
max = 50000
count = math.ceil(a/max)
for i in range(count-1):
    b = database.Find("Recommender", "UserAction_Plus", filter={"skip": i*max, "limit": (i+1)*max})
    print("ready")
    debug = 1
    for action in b:
        random_var = random.randint(0,len(article_list)-1)
        article = article_list[random_var]

        print(random_var)
        create_user = action["userpin"]
        type = action["type"]
        create_time = action["action_time"]
        if create_user not in articles[article]:
            articles[article][create_user] = 1
        else:
            continue
        document = {}
        document["type"] = type
        document["article_id"] = article
        document["create_user"] = create_user
        document["create_time"] = create_time
        document["status"] = 1
        documents.append(document)
        #print(documents)
        #mysql.Insert("rec_article", "article_action", document)
        #print(document)




